package com.checkoutcheckins.client.panels;

import com.checkoutcheckins.client.data.foursquare.FoursquareCheckins;
import com.checkoutcheckins.client.data.foursquare.FoursquareUser;
import com.checkoutcheckins.client.widgets.LoadingImage;
import com.checkoutcheckins.client.widgets.SigninWidget;
import com.checkoutcheckins.client.widgets.UserWidget;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.StackPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class WestPanel extends FlowPanel {

	private StackPanel stackPanel;

	private StatusPanel statusPanel;

	public WestPanel() {
		super();
		init();
	}

	private void init() {
		this.setStyleName("westPanel");
		Image logo = new Image("images/cocilogo_300.png");
		this.add(logo);
	}

	public void addFooter() {
		HorizontalPanel footer = new HorizontalPanel();
		footer.setStyleName("footer");
		Anchor poweredBy = new Anchor("<img src='images/poweredby.png'>", true,
				"http://www.foursquare.com");
		poweredBy.setTarget("_blank");
		Anchor followMe = new Anchor("<img src='images/followme.jpg'>", true,
				"http://www.twitter.com/CheckoutCheckin");
		followMe.setTarget("_blank");

		footer.add(poweredBy);
		footer.add(followMe);
		footer.setCellHorizontalAlignment(followMe,
				HasHorizontalAlignment.ALIGN_RIGHT);
		footer.setCellVerticalAlignment(poweredBy, HasVerticalAlignment.ALIGN_BOTTOM);
		footer.setCellVerticalAlignment(followMe, HasVerticalAlignment.ALIGN_BOTTOM);
		this.add(footer);
	}

	public void addStackedPanel(FoursquareUser fsUser) {
		System.out.println("Adding stack panel");
		stackPanel = new StackPanel();

		stackPanel.add(new LoadingImage(), "Checkins");
		stackPanel.add(new BadgesPanel(fsUser), "Badges");
		stackPanel.add(new LoadingImage(), "Mayorships");
		stackPanel.add(new LoadingImage(), "Map Settings");

		VerticalPanel bottom = new VerticalPanel();
		bottom.setWidth("100%");
		bottom.add(stackPanel);
		this.add(bottom);
		this.addFooter();
	}

	public void updateStackedPanel(FoursquareUser fsUser,
			FoursquareCheckins fsCheckins) {
		stackPanel.clear();
		stackPanel.add(new CheckinsPanel(fsUser, fsCheckins), "Checkins");
		stackPanel.add(new BadgesPanel(fsUser), "Badges");
		stackPanel.add(new MayorshipsPanel(fsUser), "Mayorships");
		
		HTML mapSettings = new HTML( 
				"Sharing options coming soon...<br>"
						+ " follow <a target='_blank' href='http://"
						+ "www.twitter.com/CheckoutCheckin'>"
						+ "@CheckoutCheckin</a> to stay updated!");
		mapSettings.setStyleName("center");
		mapSettings.addStyleName("onetwenty");
		
		stackPanel.add(mapSettings, "Map Settings");
	}

	public void addSigninWidget() {
		this.add(new SigninWidget());
	}

	public void addUserWidget(FoursquareUser fsUser, Boolean showLastSeen) {
		UserWidget userWidget = new UserWidget(fsUser, showLastSeen);
		this.add(userWidget);
	}

	public StatusPanel addStatusPanel() {
		statusPanel = new StatusPanel();
		this.add(statusPanel);
		return statusPanel;
	}

	public StackPanel getStackPanel() {
		return stackPanel;
	}

	public void setStackPanel(StackPanel stackPanel) {
		this.stackPanel = stackPanel;
	}

	public void setStatusPanel(StatusPanel statusPanel) {
		this.statusPanel = statusPanel;
	}

	public StatusPanel getStatusPanel() {
		return statusPanel;
	}

}
